<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible"
  >
    <el-form :model="dataForm"  ref="dataForm" label-width="80px">
      <el-form-item label="名称" prop="areaName">
        <el-input v-model.trim="dataForm.areaName" placeholder="请输入名称"></el-input>
      </el-form-item>
      <el-form-item label="内容" prop="content ">
        <el-input type="textarea" v-model="dataForm.content " placeholder="请输入内容"></el-input>
      </el-form-item>
<!--      <el-form-item label="时间" prop="content ">-->
<!--        <el-input v-model="dataForm.createTime " placeholder="请输入时间"></el-input>-->
<!--      </el-form-item>-->
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    name: 'patrol-add-or-update',
    data() {
      return {
        visible: false,
        areaList: [],
        dataForm: {
          areaId: '',
          areaName: '',
          createTime: '',
          content: ''
        }
      }
    },
    methods: {
      init() {
        this.visible = true
        this.getAreaList()
      },
      dataFormSubmit() {
        this.$refs['dataForm'].validate(async valid => {
          if (!valid) return
          this.loading = true
          let res = await this.$http({
            url: this.$http.adornUrl(
              `/device/area/inspection/${!this.dataForm.id ? 'save' : 'update'}`
            ),
            method: 'post',
            data: {
              areaId: this.dataForm.areaId,
              areaName: this.dataForm.areaName,
              content: this.dataForm.content,
              createTime: this.dataForm.createTime
            }
          })
          console.log(res)
          if (res && res.code === 200) {
            this.$notify.success({ title: '成功', message: '保存成功' })
            this.visible = false
            this.$emit('refreshDataList')
          } else {
            this.$notify.error({ title: '错误', message: res.msg })
          }
        })
      }
    }
  }
</script>

<style scoped>

</style>
